<template>
	<view class="changePhone">
		<comHead :title="$t('grzx.xgsjh')" :isLeft="true" :isRight="false"></comHead>
		<!-- 		<view class="text">
			<text>{{$t('grzx.bdxsjh')}}</text>
			<text>验证码已发送到尾号6207的手机号</text>
		</view> -->
		<view class="inputBox">
			<text>{{$t('grzx.qsrxsjh')}}</text>
			<input v-model="mobile" type="text" :placeholder="$t('grzx.qsrxsjh')" style="text-align: center;" />
			<!-- <text>发送验证码</text> -->
		</view>
		<view class="inputBox">
			<input v-model="captcha" type="text" :placeholder="$t('grzx.qsryzm')" />
			<text style="border-bottom: 2px solid #fff;margin-right: 40rpx;" @click="sendCaptcha">{{$t('grzx.fsyzm')}}</text>
		</view>
		<view class="btn" @click="changeMobile">
			<text>{{$t('grzx.qrbd')}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isSend: false,
				mobile: '',
				captcha: '',
			}
		},
		methods: {
			async sendCaptcha() {
				const reg = /^1[3-9]\d{9}$/;
				if (!reg.test(this.mobile)) {
					this.$tools.showTx(this.$t('grzx.qsrzqdsjh'))
				} else {
					const res = await this.$myRequest({
						url: 'api/sms/send',
						data: {
							mobile: this.mobile,
							event: 'changemobile',
						}
					});
					console.log(res);
					if(res.code == 1){
						this.isSend = true;
					}
				}
			},
			async changeMobile(){
				if(!this.isSend) return;
				if(this.captcha !== ''){
					const res = await this.$myRequest({
						url: 'api/user/changemobile',
						data: {
							mobile: this.mobile,
							captcha: this.captcha
						}
					});
					console.log(res)
					if(res.code == 1){
						this.comLink('/pages/changePhone2');
					}
				}else{
						this.$tools.showTx(this.$t('grzx.qsryzm'))
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.changePhone {
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 100vh;

		.text {
			width: 100%;
			padding: 50rpx;
			box-sizing: border-box;
			color: #fff;
			font-size: 40rpx;
			display: flex;
			flex-direction: column;

			text {
				&:nth-child(2) {
					color: #aaa;
					font-size: 26rpx;
					margin-top: 20rpx;
				}
			}
		}

		.inputBox {
			width: calc(100vw - 40rpx);
			height: 120rpx;
			padding: 0 20rpx;
			box-sizing: border-box;
			// border-radius: 0 0 20rpx 20rpx;
			border-radius: 20rpx 20rpx 0 0;
			// background: linear-gradient(110deg, #222222 0%, rgba(30, 36, 44, 0.65) 100%);
			background: linear-gradient(128deg, rgba(34, 34, 34, 0.3) 0%, rgba(30, 36, 44, 0.35) 102%);
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #fff;
			font-size: 32rpx;
			box-sizing: border-box;

			&:nth-of-type(2) {
				// border-radius: 20rpx 20rpx 0 0;
				border-radius: 0 0 20rpx 20rpx;
				border-bottom: 2rpx solid rgba(41, 41, 41);
			}

			input {
				color: #aaa;
				font-size: 26rpx;
				width: 380rpx;
				height: 80rpx;
				box-sizing: border-box;
				padding: 0 40rpx;
				border-radius: 40rpx;
				background-color: rgba(0, 0, 0, .5);
			}
		}

		.btn {
			width: 650rpx;
			height: 80rpx;
			background: linear-gradient(270deg, #5F58FD 0%, #62B6FC 100%);
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 60rpx;
			color: #fff;
			font-size: 30rpx;
			margin-top: 100rpx;
		}
	}
</style>